package cn.lizemin.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

/**
 * @author lzm
 * @Date 2024/7/27
 * @description 注意事项：每个servlet有自己独立的servlet配置，彼此之间互不影响
 * 这个servletConfig是Tomcat解析web.xml后，自动调用每个servlet的init(ServletConfig config)方法传进来的
 * 类似于spring的aware接口
 */
public class MyServlet1 extends HttpServlet {

    /**
     * 1. 获取servlet中的init-param配置信息
     */
    @Override
    public void init() throws ServletException {
        ServletConfig config = this.getServletConfig();
        Enumeration<String> params = config.getInitParameterNames();
        while (params.hasMoreElements()) {
            String name = params.nextElement();
            String value = config.getInitParameter(name);
            System.out.println(name + " = " + value);
        }
        System.out.println(params);
    }

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.service(req, resp);
    }


}
